package yanivosher.aiproject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class TerroristBNN extends BasianNetworkNode {
	
	Edge edge;
	
	public TerroristBNN(ArrayList<BasianNetworkNode> parents,Edge e) {
		super(parents);
		this.edge = e;
		this.probTable = buildProbTable();
	}
	
	private HashMap<String, Float> buildProbTable()
	{
		HashMap<String, Float> retMap = new HashMap<String, Float>();
		
		//army 1, not army 2, not chem reported 1, not chem reported 2
		float q1 = 1 - (float) (Environment.armyProb*Math.max((5-edge.getWeight())/5, 0.3));
		//not army 1, not army 2, chem reported 1, not chem reported 2
		float q2 = 1 - (float) (Environment.chemProb*Math.max((5-edge.getWeight())/5, 0.3));
		//not army 1, army 2, not chem reported 1, not chem reported 2
		float q3 = 1 - (float) (Environment.armyProb*Math.max((5-edge.getWeight())/5, 0.3));
		//not army 1, not army 2, not chem reported 1, chem reported 2
		float q4 = 1 - (float) (Environment.chemProb*Math.max((5-edge.getWeight())/5, 0.3));
		
		for (int i = 0; i < 16; i++) {
			boolean b1 = (i/8)%2 == 0;
			boolean b2 = (i/4)%2 == 0;
			boolean b3 = (i/2)%2 == 0;
			boolean b4 = (i/1)%2 == 0;
			float p1 = b1? q1 : 1;
			float p2 = b2? q2 : 1;
			float p3 = b3? q3 : 1;
			float p4 = b4? q4 : 1;
			
			//System.out.println(getStringFromParents(Arrays.asList(b1,b2,b3,b4)));
			retMap.put(getStringFromParents(Arrays.asList(b1,b2,b3,b4)), 1 - p1*p2*p3*p4);
		}
		return retMap;
	}
}
